package com.acme.bankapp.domain.bank;

public abstract class AbstractAccount implements Account {

	static protected int idCounter;
	protected int id;
	protected double balance;
	
	@Override
	public String toString() {
		return "Account[id=" + id + ", balance=" + balance + "]";
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * (int)balance;
		result = prime * result + id;
		return result;
	}

	public AbstractAccount(final double amount) {
		this.balance = amount;
		id=idCounter++;
	}

	public double getBalance() {
		return balance;
	}

	public void deposit(double amount) {
		balance += amount;
	};

	public void withdraw(double amount) {
		if (amount <= balance) {
			balance -= amount;
		} else {
			System.out.println("Error: withdraw failed");
		}
	};
	

	public double getMaximumAmountToWithdraw() {
		return (balance);
		
	}
	
	public int decimalValue() {
		return (int)(Math.round(getBalance()));
		
	}
	

}
